package com.xx.sg.controller;

import com.xx.sg.util.FileUploadUtils;
import com.xx.sg.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Tag(name = "文件上传", description = "文件上传API")
public class FileUploadController {

    @Value("${sg.profile}")
    private String profile;

    @PostMapping(path = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "文件上传", description = "文件上传")
    public R importResource(@RequestParam("file") MultipartFile file,
                            @RequestParam String dirName) {

        String filePath = FileUploadUtils.uploadFile(profile, dirName, file);
        return R.success(filePath);
    }
}
